{extend name="layout" /}
{block name="content"}
<div class="row">
  <div class="col-xs-3">
    <form>
      <div class="input-group input-group-sm demoTable">
          <input type="text" class="form-control input-sm" name="keywords" id="demoReload" autocomplete="off"><!-- keywords -->
          <span class="input-group-btn">
            <button class="btn btn-info btn-flat layui-btn" data-type="reload">搜  索</button>
          </span>
      </div>
    </form>
  </div>
  <div class="col-xs-9" style="text-align: right">
    <button type="button" class="btn btn-success btn-sm cocoModal" isForm url="{:url('add', ['pid'=>$pid])}" title="新增项目" fixat="1"><i class="fa fa-plus"></i> 新增</button>
  </div>
</div>
<table class="layui-table" lay-data="{height: 'full-75', cellMinWidth: 80, page: true, id:'lists',limit:30, url:'{:url('data_show_where',['whereData'=>$whereData])}'}" lay-filter="lists">
  <thead>
    <tr>
      <th lay-data="{type:'checkbox'}">ID</th>
      <th lay-data="{field:'id', sort: true, fixed: 'right', width:80, align:'center'}">ID</th>
      <th lay-data="{field:'title'}">名称</th>
      <th lay-data="{field:'fullname'}">全称</th>
      <th lay-data="{field:'pname'}">上级</th>
      <th lay-data="{field:'salestate'}">销售状态</th>
      <th lay-data="{field:'hidename'}">是否隐藏</th>
      <th lay-data="{field:'recom'}">是否推荐</th>
      <th lay-data="{field:'listorder', edit: 'text'}">排序</th>
      <th lay-data="{fixed: 'right', width:200, align:'center', toolbar: '#barDemo'}">操作</th>
    </tr>
  </thead>
</table>
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  <a class="layui-btn layui-btn-xs" lay-event="child">查看子菜单</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
{/block}
{block name="script"}
<script type="text/javascript">
  layui.use('table', function(){
    var table = layui.table;
    var $ = layui.$, active = {
      reload: function(){
        var demoReload = $('#demoReload');
        //执行重载
        table.reload('lists', {
          page: {
            curr: 1 //重新从第 1 页开始
          }
          ,where: {
            key: {
              keywords: demoReload.val()
            }
          }
        });
      }
    };
    $('.demoTable .layui-btn').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
  });
</script>
<script type="text/javascript">
  function child(data){
    if (data.depth == 4) {
      layer.msg('下级菜单为空');
      return false;
    }
    if (data.depth == 3) {
      location.href = APP_URL + '/admin/car/index?pid=' + data.id;
    }else{
      location.href = APP_URL + window.location.pathname + '?pid=' + data.id;
    }
  }
</script>
{/block}